package com.whiteape.book.ui.base;


import androidx.fragment.app.Fragment;

import com.whiteape.book.R;
import com.whiteape.book.widget.tabcontainer.TabContainerView;
import com.whiteape.book.widget.tabcontainer.adapter.DefaultAdapter;

import butterknife.BindView;

/**
 * Created by newbiechen on 17-4-24.
 */

public abstract class BaseTabNavigaterActivity<T extends BaseContract.BasePresenter> extends BaseMVPActivity<T> {
    /**************View***************/
    @BindView(R.id.tab_container_view)
    protected TabContainerView tabContainerView;
    protected Fragment[] mFragmentArr;
    private String[] tabTitleArray;
    private int[] iconNormalArr;
    private int[] iconSelectedArr;

    /**************abstract***********/
    protected abstract Fragment[] createTabFragments();

//    protected abstract List<String> createTabTitles();

    protected abstract String[] createTitleArray();

    protected abstract int[] createIconNormalArray();

    protected abstract int[] createIconSelectedArray();

    @Override
    protected void initView() {
        super.initView();
        setUpTabLayout();
    }

    /*****************rewrite method***************************/


    private void setUpTabLayout() {
        mFragmentArr = createTabFragments();
        tabTitleArray = createTitleArray();
        iconNormalArr = createIconNormalArray();
        iconSelectedArr = createIconSelectedArray();

        DefaultAdapter defaultAdapter = new DefaultAdapter(this, mFragmentArr, getSupportFragmentManager(), tabTitleArray,
        R.color.md_dark_primary_text, iconNormalArr, iconSelectedArr);
        tabContainerView.setAdapter(defaultAdapter);


    }

    public Fragment getCurrentFragment() {
        if (mFragmentArr == null) {
            return null;
        }
        return mFragmentArr[tabContainerView.getCurrentItem()];
    }

}
